module DisOrder
  module Helpers

    def render_markdown(content)
      markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
      return markdown.render(content)
    end

    def config(parameter)
      config = YAML.load_file("config.yml")
      return config[parameter] if parameter
    end

    def baseTemplate
      baseTemplate ||= File.new(config("baseTemplateFolder") + "/"+ config("baseTemplateFile"), encoding: "UTF-8").read
    end

    def indexTemplate
      indexTemplate ||= File.new(config("baseTemplateFolder")+ "/" + config("indexHtml"), encoding: "UTF-8").read
    end

    def articlesData
      path = config("baseMetaDataFolder") + "/" + config("metaDataFileArticels")
      return YAML.load_file(path) if File.exist?(path)
    end

    def baseURL
      return config("baseurl")
    end

    def outputImages
      config("output") + "/static/images"
    end

    def outputCSS
      config("output") + "/static/css"
    end

    def outputFonts
      config("output") + "/static/fonts"
    end

    def outputJS
      config("output") + "/static/js"
    end

    def sanitize_filename(filename)
      filename = filename.gsub(/^.*(\\|\/)/, '')
      filename = filename.gsub(/[^0-9A-Za-z.\-]/, '_')
      filename = filename.downcase
      return filename
    end

    def self.isDisOrderProject?
      return File.exist?("config.yml") ? true : false
    end
  end
end